<?php

namespace app\user\controller;

use app\common\controller\CommonController;
use app\common\controller\ResponseJson;
use app\common\entity\RequestEntity;
use think\Db;

class Staffcost extends CommonController{
    public function ListCost(){
        $param_page = $get_page = input('Page', 1);
        $param_pagesize =  10;
        $get_keyword = new RequestEntity('search_key', '搜索内容', false, 0);
        $where = '1=1';
        if(!empty($get_keyword->text)){
            $where .= ' and nick_name  like "' . $get_keyword->text.'%"';
        }
        $res = Db::name('staff')
            ->field([
                'staff_id'=>'Id',
                'number'=>'StaffNumber',//工号
                'nick_name'=>'Name',
                'count'=>'Count',//刷卡记录次数
                'phone_number'=>'Phone'
            ])
            ->where($where)
            ->limit(($param_page - 1) * $param_pagesize, $param_pagesize)
            ->select();
        foreach ( $res as $key => $value){
            $res[$key]['Order'] = $key + 1;
        }
        $int_total_count = Db::table('staff')->count();
        $data['tableData']=$res;
        $data['TotalCount'] = $int_total_count;
        $data['Page'] = (int)$param_page;
        $data['PageSize'] = (int)$param_pagesize;
        return ResponseJson::Json($data);
    }
    public function ItemCost(){
        $Id = new RequestEntity('Id', 'Id', false, 32);
        $res = Db::name('staff')->alias('s')
            ->field('s.number as StaffNumber,s.nick_name as Name,s.count as Count,s.phone_number as Phone')
            ->join('department d', 's.department_id = d.depart_id')
            ->where('s.staff_id ='.$Id->text)
            ->select();
        return ResponseJson::Json($res);
    }
    public function haha(){
        var_dump(md5('jltf1'));
    }
}